package com.miracle9.game.dao;

import com.miracle9.game.entity.Activity;

import java.util.List;

import org.hibernate.Query;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

@Repository
public class ActivityServiceDao extends SqlOperating<Activity, Integer> {

    public int getQuantity() {
        return q_CreateSqlInt("select count(*) from Activity", new Object[0]);
    }

    @Cacheable(value = {"springCache"}, key = "'getActivityList'")
    public List<Activity> getActivityList() {
        return q_CreateSqlList("from Activity order by type,condition1", new Object[0]);
    }

    public List<Activity> getActivitysByIdSQL(int nType) {
        return q_CreateSqlList("from Activity where type=? order by condition1", new Object[]{Integer.valueOf(nType)});
    }

    public int getQuantityByTypeOrderby(int nTypeId) {
        String hql = "select count(*) from Activity where type =? order by condition1";
        Object sum = q_CreateSql("select count(*) from Activity where type =? order by condition1", new Object[]{Integer.valueOf(nTypeId)}).uniqueResult();
        if (sum == null) {
            return 0;
        }
        return ((Number) sum).intValue();
    }

}